<?php
/*****************************************
Wer Wird Millionär
TIT10NS Webengeneering Projekt

TGameView - Eine View-Klasse für das Spiel.

Autoren: Francesco Silvani
Copyright: 2012 DHBW Mannheim
*****************************************/

class TGameView extends TView{
  public function echoPlayerName($name){
        echo        '<div class="playername">
                                <h1 class="playername"><span class="invisible">Spieler:&nbsp;</span>'.$name.'</h1>
                        </div>';
  }

  public function echoResults($resultArray,$thisLevel,$isRisk){
    echo '<div id="result">
                        <ul class="resultlist">
						<h1 class="invisible">Ergebnis:</h1>';
                                for ($i=15;$i>0;$i--){
                                  if ($thisLevel==$i){
                                        echo '<li class="selected"><span class="invisible"><</span>'.$i.' '.$resultArray[$i].'<span class="invisible">></span></li>';
                                  }else{
                                        if ($i==5 || ($i==10 && !$isRisk)){
                                          echo '<li class="fallback"><span class="invisible">Sicherung:</span>'.$i.' '.$resultArray[$i].'</li>';
                                        }else{
                                          echo '<li>'.$i.' '.$resultArray[$i].'</li>';
                                        }
                                  }
                                }

    echo'               </ul>
         </div>';
  }

  public function echoJokers($ffjoker,$telejoker,$audjoker,$riskjoker){
   echo '<div id="gamebuttons">
            <form action="?" method="post">
				<button class="quit" value="quit" name="quit" type="submit"><span class="invisible">'.parent::getText('leave').'</span></button>
				<ul class="joker">
				<h1 class="invisible">Joker: </h1>
						<li class="fiftyfiftyjoker'. ($ffjoker?  "":" used").'"><'.($ffjoker?  'button name="joker" value="5050Joker"      type="submit"':"span").' class="joker"><span class="invisible">'.parent::getText('5050Joker')     .'</span></button></li>
						<li class="telephonejoker'.  ($telejoker?"":" used").'"><'.($telejoker?'button name="joker" value="TelephoneJoker" type="submit"':"span").' class="joker"><span class="invisible">'.parent::getText('TelephoneJoker').'</span></button></li>
						<li class="audiencejoker'.   ($audjoker? "":" used").'"><'.($audjoker? 'button name="joker" value="AudienceJoker"  type="submit"':"span").' class="joker"><span class="invisible">'.parent::getText('AudienceJoker') .'</span></button></li>
						<li class="riskjoker'.       ($riskjoker?"":" used").'"><'.($riskjoker?'button name="joker" value="RiskJoker"      type="submit"':"span").' class="joker"><span class="invisible">'.parent::getText('RiskJoker')     .'</span></button></li>
				</ul>
            </form>
        </div>';
  }

  public function echoQuestion($Q,$A,$B,$C,$D,$right,$wrong,$erase_answers){
    echo'<div class="gamequestion">
			<h1 class="invisible">Frage: </h1>
			<p id="question_text">'.$Q.'</p>
         </div>

         <div id="answer">
				'.(($right=="" && $wrong=="")?'<form action="?" method="post">':'').'
				 <ul class="answerlist">
				 <h1 class="invisible">Antwortmöglichkeiten: </h1>
									<li><h2 class="answerlist">A:</h2>'.($erase_answers[0]=="A"||$erase_answers[1]=="A"?"":'<button class="'.$this->getClasses($right,$wrong,"A").'answerlist" type="submit" name="answer" value="A">'.$A.'</button>').'</li>
									<li><h2 class="answerlist">B:</h2>'.($erase_answers[0]=="B"||$erase_answers[1]=="B"?"":'<button class="'.$this->getClasses($right,$wrong,"B").'answerlist" type="submit" name="answer" value="B">'.$B.'</button>').'</li>
									<li><h2 class="answerlist">C:</h2>'.($erase_answers[0]=="C"||$erase_answers[1]=="C"?"":'<button class="'.$this->getClasses($right,$wrong,"C").'answerlist" type="submit" name="answer" value="C">'.$C.'</button>').'</li>
									<li><h2 class="answerlist">D:</h2>'.($erase_answers[0]=="D"||$erase_answers[1]=="D"?"":'<button class="'.$this->getClasses($right,$wrong,"D").'answerlist" type="submit" name="answer" value="D">'.$D.'</button>').'</li>
				 </ul>
			'.(($right=="" && $wrong=="")?'</form>':'').'
         </div>';
  }

  private function getClasses($right,$wrong,$answer){
    if ($answer==$wrong){
      $ret="wrong ";
    }elseif ($answer==$right){
      $ret="right ";
    }else{
      $ret="";
    }
    return $ret;
  }

  public function echoSuccess(){
    echo '<div class="message"><div class="messagetext">'.parent::getText('successtext').'<form action="?" method="post"></br><button class="proceed" type="submit" name="proceed" value="proceed">'.parent::getText('proceed').'</button></form></div></div>';
  }

  public function echoLose($result){
    echo '<div class="message"><div class="messagetext">'.sprintf(parent::getText('losetext'),$result).'<form action="?" method="post"></br><button class="newgame" type="submit" name="new" value="new">'.parent::getText('new').'</button></form></div></div>';
  }

  public function echoLeave(){
    echo '<div class="message"><div class="messagetext">'.parent::getText('leavetext').'<form action="?" method="get"></br><button class="newgame" type="submit" name="new" value="new">'.parent::getText('new').'</button></form></div></div>';
  }

  public function echoWin(){
    echo '<div class="message"><div class="messagetext">'.parent::getText('wintext').'<form action="?" method="get"></br><button class="newgame" type="submit" name="new" value="new">'.parent::getText('new').'</button></form></div></div>';
  }

  public function echoJokerAnswer($joker,$jokeranswer){

    switch ($joker){
    case "AudienceJoker":
      echo '<div class="message"><div class="joker_view"><p class="invisible">Ergebnis des Publikumsjokers</p>
        <div id="audience">

          <div id="audience_resultbox">

            <div id="A" class="audience_results" style="height:'.$jokeranswer["A"].'%"><p class="invisible"> A: </p><p id="audience_result_text">'.$jokeranswer["A"].'%</p></div>
            <div id="B" class="audience_results" style="height:'.$jokeranswer["B"].'%"><p class="invisible"> B: </p><p id="audience_result_text">'.$jokeranswer["B"].'%</p></div>
            <div id="C" class="audience_results" style="height:'.$jokeranswer["C"].'%"><p class="invisible"> C: </p><p id="audience_result_text">'.$jokeranswer["C"].'%</p></div>
            <div id="D" class="audience_results" style="height:'.$jokeranswer["D"].'%"><p class="invisible"> D: </p><p id="audience_result_text">'.$jokeranswer["D"].'%</p></div>

          </div>

        </div>
      </div></div>';
      break;
    case "TelephoneJoker":
		$telejoker=array_keys($jokeranswer);
		$answer=$telejoker[0];
		$probability=$jokeranswer[$answer];
		
		echo'<div class="message"><div class="joker_view"><p class="invisible">Ergebnis des '.$joker.'</p>
			 <div id="risk_telephone">

			 <div id="risk_telephone_text">';
				if (empty($jokeranswer)==true){
					echo parent::getText('TelephoneJokerEmpty');
				}else{
				echo sprintf(parent::getText('TelephoneJokerAnswer'),$answer,$probability);
				}
			echo'</div>
		  
        </div>
      </div></div>';
	break; 
    case "RiskJoker":
		$riskjoker=array_keys($jokeranswer);
		$answer=$riskjoker[0];
		$probability=$jokeranswer[$answer];
		
		echo'<div class="message"><div class="joker_view"><p class="invisible">Ergebnis des '.$joker.'</p>
			 <div id="risk_telephone">

			 <div id="risk_telephone_text">';
				
				echo sprintf(parent::getText('RiskJokerAnswer'),$answer,$probability);
				
			echo'</div>
		  
        </div>
      </div></div>';
      break;
    case "5050Joker":
      echo '<p class="invisible">Ergebnis des '.$joker.'</p><div class="invisible">'.sprintf(parent::getText('5050JokerAnswer'),$jokeranswer[0],$jokeranswer[1]).'</div>';
      break;
    }
  }


  public function echoStartGameBegin(){
    echo '<form action="?" method="post">';
  }
  public function echoStartGameEnd(){
    echo '</form>';
  }

  public function echoCategorys($categorys){
    echo '<div id="result">
          <select name="category" class="pregamecat" size="17">
                        <option value="-1" selected="selected">'.parent::getText('all').'</option>';

                        foreach ($categorys as $key=>$value){
                          echo '<option value="'.$key.'" >'.$value.'</option>';
                        }

    echo'        </select>
        </div>';
  }

  public function echoStartGameButtons(){
    echo'<div class="gamequestion">
                        <p id="question_text">'.self::getText('startgame').'</p>
             </div>    

         <div id="answer">
                    <ul class="answerlist">
                                                        <li><h2 class="answerlist">A:</h2><button class="answerlist" type="submit" name="startGame" value="risk">'.  self::getText('risk')  .'</button></li>
                                                        <li><h2 class="answerlist">B:</h2><button class="answerlist" type="submit" name="startGame" value="norisk">'.self::getText('norisk').'</button></li>
                    </ul>
         </div>';
  }

  public function echoPlaceboJokers($ffjoker=true,$telejoker=true,$audjoker=true,$riskjoker=true){
   echo '<div id="gamebuttons">
            <span class="quit"></span>
			<ul class="joker">
					<li class="fiftyfiftyjoker'. ($ffjoker?  "":" used").'"><span class="joker"></span></li>
					<li class="telephonejoker'.  ($telejoker?"":" used").'"><span class="joker"></span></li>
					<li class="audiencejoker'.   ($audjoker? "":" used").'"><span class="joker"></span></li>
					<li class="riskjoker'.       ($riskjoker?"":" used").'"><span class="joker"></span></li>
			</ul>
        </div>';
  }

}
?>